home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / epugui / epu_gui.bb2 < prev    next >
Text File  |  1995-03-09  |  15KB  |  632 lines

  1. ;EPU GUI by Code 16 (David Linsley & Chris Redpath). June-Oct 1994
  2.  
  3. If NOT(FromCLI)
  4.   WBStartup         ;If run from Workbench then legally startup
  5.   WbToScreen 0      ;and open on Workbench screen
  6. Else
  7.   FindScreen 0      ;else open on front screen
  8. EndIf
  9. NoCli
  10.  
  11. DecodeShapes 0,?fileicon   ; Decode included File Requester Icon
  12.                            ; Come on Simon include it as a command!
  13. ;Open program icon
  14. success1.w=GetIconInfo(0,"PROGDIR:EPU_GUI")
  15. If success1=True
  16.   defdevice$=IconTool$(0,"DEVICE")   ; Read in Tooltype values
  17.   hotkey$=IconTool$(0,"CX_POPKEY")
  18.   openwin.w=NOT(IconSubTool$(IconTool$(0,"CX_POPUP"),"NO"))
  19.   If hotkey$=""
  20.     hotkey$="ctrl lalt e"  ; If no hotkey tooltype then set a default
  21.   EndIf EndIf Free IconInfo 0 ; Close Icon.
  22.  
  23. ;Make the Program a Commodity and set its kotkey.
  24. success2=MakeCommodity("EPU_GUI","EPU-GUI "+Chr$(169)+" D Linsley and C Redpath","GUI for EPU - THE disc expander")
  25. success3=SetHotKey(0,hotkey$)
  26.  
  27. ;If the icon, commodity or hotkey could not be found/set then exit.
  28. If (success1 AND success2 AND success3)=False Then End
  29.  
  30. wintit$="EPU GUI by Code 16: Hotkey=<"+hotkey$+">" ;window title
  31. appear.b=False      ; Sate of interface - False = window closed
  32.  
  33. ;If another copy is runing then exit - so they dont get confused :-)
  34. If CommodityEvent=True
  35.   em.l=ExchangeMessage
  36.   Select em
  37.     Case CxUnique
  38.       End
  39.   End Select
  40. EndIf
  41.  
  42. ;Structure to store and send data to EPU
  43. NEWTYPE .epudata
  44.   dev.s
  45.   load.b
  46.   save.b
  47.   exam.b
  48.   exnext.b
  49.   hmode.b
  50.   blocksize.w
  51.   table.l
  52.   lib.s
  53. End NEWTYPE
  54.  
  55. ;Structure to store list of libraries for a gadtools List-View gadget
  56. NEWTYPE .dir
  57.   word.w
  58.   name.s
  59. End NEWTYPE
  60.  
  61.  
  62. MaxLen pa$=192
  63. MaxLen fi$=128
  64.  
  65. Dim List directory.dir(32)   ; Maximum compression libraries
  66. Dim List inputbuffer$(10)    ; Store to load epu info file
  67.  
  68. ;Run EPU as a CLI command with paramaters.
  69. Statement run_epu{parm$,device$}
  70. parm$="EPU DEV "+device$+" "+parm$+" CHNG"
  71. Execute_ &parm$,0,0
  72. End Statement
  73.  
  74. ;Run EPU, store and process the data returned
  75. Function.w get_epudata{device$}
  76. SHARED inputbuffer$(),wintit$,appear
  77.  
  78. ;Dont change title of screen if window not open!
  79. If appear=True
  80.   WLocate 2,86
  81.   WTitle wintit$,"EPU installed on device "+device$+":"
  82. EndIf
  83.  
  84. ClearList inputbuffer$()
  85.  
  86. ;Run EPU and save data as a file in T:
  87. parm$="EPU DEV "+Chr$(34)+device$+Chr$(34)+" INFO >t:epudata"
  88. Execute_ &parm$,0,0
  89.  
  90. ResetList inputbuffer$()
  91.  
  92. ; Read in the info file showing current status of epu device specified
  93. If ReadFile(0,"t:epudata")
  94.   FileInput 0
  95.   count.b=0
  96.   Repeat
  97.     If AddItem(inputbuffer$())
  98.       inputbuffer$()=Edit$(80)
  99.     EndIf
  100.     count+1
  101.   Until count>5 OR Eof(0)
  102.   CloseFile 0
  103.   comm$="delete t:epudata >nil:" ; Delete the info file
  104.   Execute_ &comm$,0,0
  105. EndIf
  106.  
  107. ; Initialise Data
  108. ResetList inputbuffer$()
  109. devdata.epudata\load=0
  110. USEPATH devdata.epudata
  111. \load=False
  112. \save=False
  113. \exam=False
  114. \exnext=False
  115. \hmode=False
  116. \blocksize=0
  117. \table=0
  118. \lib=""
  119. devinst.w=0
  120.  
  121. ;Process returned file and set structure accordingly.
  122. If NextItem(inputbuffer$())
  123. If Instr(UCase$(inputbuffer$()),"EPU ")<=0
  124.   devinst.w=2  ; 0=not installed, 1=installed, 2=device non-existant.
  125.  
  126.   ;If EPU is installed on the device then process the data.
  127.   If Instr(UCase$(inputbuffer$()),"DEVICE")<=0
  128.     devinst.w=1
  129.     While NextItem(inputbuffer$())
  130.       temp$=UCase$(inputbuffer$())
  131.       If Instr(temp$," LOAD ")
  132.         \load=True
  133.       EndIf
  134.       If Instr(temp$," SAVE ")
  135.         \save=True
  136.       EndIf
  137.       If Instr(temp$," EXAM ")
  138.         \exam=True
  139.       EndIf
  140.       If Instr(temp$," EXNEXT ")
  141.         \exnext=True
  142.       EndIf
  143.       If Instr(temp$," HMODE")
  144.         \hmode=True
  145.       EndIf
  146.       If Instr(temp$,"BLOCK")
  147.         posn=Instr(temp$,":")
  148.         If posn>0
  149.           \blocksize=Val(Right$(temp$,Len(temp$)-posn))
  150.         ;****** Debug Info ******
  151.         ;NPrint \blocksize
  152.         EndIf
  153.       EndIf
  154.       If Instr(temp$,"TABLE")
  155.         posn=Instr(temp$,":")
  156.         If posn>0
  157.           \table=Val(Right$(temp$,Len(temp$)-posn))
  158.         ;****** Debug Info ******
  159.         ;NPrint \table
  160.         EndIf
  161.       EndIf
  162.       If Instr(temp$,"LIBRARY")
  163.         posn=Instr(temp$,":")
  164.         If posn>0
  165.           temp$=StripLead$(Right$(temp$,Len(temp$)-posn),32)
  166.           If Left$(temp$,1)="E"
  167.             \lib=Left$(temp$,4)
  168.           Else
  169.             \lib=Mid$(temp$,4,Len(temp$)-3)
  170.           EndIf
  171.         ;****** Debug Info ******
  172.         ;NPrint \lib
  173.         EndIf
  174.       EndIf
  175.     Wend
  176.   EndIf
  177. EndIf
  178. EndIf
  179.  
  180. ;Set default tag value and set the gadtools to the correct state.
  181. tag.l=$80080000
  182. GTSetAttrs 0,14,tag+4,\load*-1
  183. GTSetAttrs 0,1,tag+4,\save*-1
  184. GTSetAttrs 0,2,tag+4,\exam*-1
  185. GTSetAttrs 0,3,tag+4,\exnext*-1
  186. GTSetAttrs 0,4,tag+4,\hmode*-1
  187. GTSetInteger 0,5,\blocksize
  188. GTSetInteger 0,6,\table
  189. GTSetString 0,7,\lib
  190. Function Return devinst.w  ; return value of EPU installed on that device
  191. End Function
  192.  
  193. ;Display warning and set structures if EPU is not installed on the device
  194. Statement not_installed{inst.w}
  195. SHARED wintit$,appear
  196.  
  197. If appear=True
  198.   WLocate 2,86
  199. EndIf
  200.  
  201. If inst=0                  ;Not installed
  202.   ; Initialise Data
  203.   devdata.epudata\load=0
  204.   USEPATH devdata.epudata
  205.   \load=True
  206.   \save=False
  207.   \exam=True
  208.   \exnext=True
  209.   \hmode=True
  210.   \blocksize=30
  211.   \table=1000
  212.   \lib="NUKE"
  213. If appear=True
  214.   WTitle wintit$,"EPU is not installed on this device!"
  215. EndIf
  216.  
  217. Else
  218.  
  219. If appear=True
  220.   WTitle wintit$,"Device does not exist!"
  221. EndIf
  222. ; Initialise Data
  223.   devdata.epudata\load=0
  224.   USEPATH devdata.epudata
  225.   \load=False
  226.   \save=False
  227.   \exam=False
  228.   \exnext=False
  229.   \hmode=False
  230.   \blocksize=0
  231.   \table=0
  232.   \lib=""
  233. EndIf
  234.  
  235. ; set gadtools to the correct status
  236.  
  237.   tag.l=$80080000
  238.   GTSetAttrs 0,14,tag+4,\load*-1
  239.   GTSetAttrs 0,1,tag+4,\save*-1
  240.   GTSetAttrs 0,2,tag+4,\exam*-1
  241.   GTSetAttrs 0,3,tag+4,\exnext*-1
  242.   GTSetAttrs 0,4,tag+4,\hmode*-1
  243.   GTSetInteger 0,5,\blocksize
  244.   GTSetInteger 0,6,\table
  245.   GTSetString 0,7,\lib
  246.  
  247. BeepScreen 0 ; Flash the screen to give audio/visual warning
  248.  
  249. End Statement
  250.  
  251. ;Make the parameter string to pass to EPU from the gadtools setting
  252. Function.s make_string{}
  253. tag.l=$80080000+4
  254. parm$="EPU DEV "+Chr$(34)      ; 34= "
  255. device$=GTGetString(0,8)
  256. posn=Instr(device$,":")        ; Strip colon off the device name
  257. If posn>0
  258.   device$=Left$(device$,posn-1)
  259.   parm$+device$+Chr$(34)+" "
  260.   If GTStatus(0,1) <>0
  261.     parm$+"SAVE "
  262.   Else
  263.     parm$+"NOSAVE "
  264.   EndIf
  265.   If GTStatus(0,14)<>0
  266.     parm$+"LOAD "
  267.   Else
  268.     parm$+"NOLOAD "
  269.   EndIf
  270.   If GTStatus(0,2)<>0
  271.     parm$+"EXAM "
  272.   Else
  273.     parm$+"NOEXAM "
  274.   EndIf
  275.   If GTStatus(0,3)<>0
  276.     parm$+"EXNEXT "
  277.   Else
  278.     parm$+"NOEXNEXT "
  279.   EndIf
  280.   If GTStatus(0,4)<>0
  281.     parm$+"HMODE "
  282.   Else
  283.     parm$+"LMODE "
  284.   EndIf
  285.   parm$+"BLOCK "+Str$(GTGetInteger(0,5))+" "
  286.   parm$+"TABLE "+Str$(GTGetInteger(0,6))+" "
  287.   parm$+"LIB "+GTGetString(0,7)
  288. EndIf
  289.   Function Return(parm$)
  290. End Function
  291.  
  292.  
  293. ; Actual MAIN PROGRAM
  294.  
  295. state.b=True       ; State of CX - True = enabled
  296.  
  297. SetStatus On       ; Set Commodity status (for Exchange program)
  298.  
  299. ClearList directory()
  300. ResetList directory()
  301.  
  302. ;Find EPU and XPK compression libraries, and place them in a link-list
  303. ChDir "LIBS:"
  304. entries.w=0
  305.  
  306. While MoreEntries  ; More files in libs: 
  307.   fi$=UCase$(EntryName$) 
  308.   If Right$(fi$,8)=".LIBRARY" AND NOT(EntryDIR)    ; XPK lib?
  309.   If Left$(fi$,3)="XPK" AND Len(fi$)=15
  310.     fi$=Mid$(fi$,4,4)
  311.     If AddItem(directory())
  312.       directory()\name=fi$
  313.       entries+1
  314.     EndIf
  315.   EndIf
  316.   If Left$(fi$,3)="EPU"                            ; EPU lib?
  317.     fi$=Left$(fi$,4)
  318.     If AddItem(directory())
  319.       directory()\name=fi$
  320.       entries+1
  321.     EndIf
  322.   EndIf
  323.   EndIf
  324. Wend
  325.  
  326. ;Create the gadgets using WB2 and up gadtools.
  327. GTListView 1,0,12,0,140,100,"",0,directory()
  328. GTCheckBox 0,14,80,8,16,12,"Load  ",1
  329. GTCheckBox 0,1,80,20,16,12,"Save  ",1
  330. GTCheckBox 0,2,80,32,16,12,"Exam  ",1
  331. GTCheckBox 0,3,80,44,16,12,"ExNext",1
  332. GTCheckBox 0,4,80,56,16,12,"Hmode ",1
  333. GTInteger  0,5,80,70,64,12,"Block ",1,10
  334. GTInteger  0,6,220,70,96,12,"Table  ",1,1000
  335. GTString   0,7,220,54,96,12,"Library",1,16,"NUKE"
  336. GTString   0,8,220,8,96,12,"Device ",1,16,defdevice$ ; from tooltype
  337. GTShape    0,9,320,8,0,0
  338. GTShape    0,10,320,54,0,0
  339. GTButton   0,11,156,22,80,12,"Install",$10
  340. GTButton   0,12,256,22,80,12,"Remove",$10
  341. GTButton   0,13,156,38,180,12,"Modify User-Startup",$10
  342. GTButton   0,15,320,70,40,12,"Quit",$10
  343.  
  344. ;Set a required IDCMP flag for gadtools.
  345. AddIDCMP $400010
  346.  
  347. ;If CX_POPUP=YES then open the window.
  348. If openwin=True
  349.   Gosub _appear
  350. EndIf
  351.  
  352. ;****** Debug Info ******
  353. ;Window 3,30,150,128,90,$100f,"Gadget Status",1,2
  354.  
  355. ;Get EPU data for the default device in the ToolTypes.
  356. device$=GTGetString(0,8)
  357. posn=Instr(device$,":")
  358. If posn>0
  359.   device$=Left$(device$,posn-1)
  360.   inst.w=get_epudata{device$}
  361.   If inst<>1
  362.     not_installed{inst}
  363.   EndIf
  364. Else
  365.   BeepScreen 0   ; Beep screen if no device
  366. EndIf
  367.  
  368. tag.l=$80080000
  369.  
  370. ;Wait for an event to our program - intuition, Commodity or hotkey
  371. ;Make sure it was for our window if an intuievent.
  372. Repeat
  373.   Repeat
  374.     VWait
  375.     ev.l=Event
  376.     ce.l=CommodityEvent
  377.     hk.l=HotKeyHit
  378.   Until (((ev=$200 OR ev=$40) AND EventWindow=0) OR ce=True OR hk=0)
  379.  
  380.   gad.w=GadgetHit
  381.   eve.w=EventCode
  382.  
  383.   ;Close the window if close gadget selected (hide interface)
  384.   If ev=$200
  385.     Gosub _disappear
  386.   EndIf
  387.  
  388. ;Process Exchange message and set interface accordingly
  389.   If ce=True
  390.     em.l=ExchangeMessage
  391.     Select em
  392.       Case CxAppear
  393.         Gosub _appear
  394.       Case CxDisAppear
  395.         Gosub _disappear
  396.       Case CxEnable
  397.         Gosub _enable
  398.       Case CxDisable
  399.         Gosub _disable
  400.       Case CxKill
  401.         Goto _kill
  402.     End Select
  403.   EndIf
  404.  
  405. ;Open display if the hotkey was pressed
  406.   If hk=0 Then Gosub _appear
  407.  
  408. ;If gadget selected then do the right thing
  409.   Use Window 0
  410.   If ev=$40 AND state=True AND appear=True
  411.  
  412. ;For gadgets 14,1-7 then RUN EPU to set the value
  413.     Select gad
  414.       Case 14
  415.         If eve=0
  416.           parm$="NOLOAD"
  417.         Else
  418.           parm$="LOAD"
  419.         EndIf
  420.         run_epu{parm$,device$}
  421.       Case 1
  422.         If eve=0
  423.           parm$="NOSAVE"
  424.         Else
  425.           parm$="SAVE"
  426.         EndIf
  427.         run_epu{parm$,device$}
  428.       Case 2
  429.         If eve=0
  430.           parm$="NOEXAM"
  431.         Else
  432.           parm$="EXAM"
  433.         EndIf
  434.         run_epu{parm$,device$}
  435.       Case 3
  436.         If eve=0
  437.           parm$="NOEXNEXT"
  438.         Else
  439.           parm$="EXNEXT"
  440.         EndIf
  441.         run_epu{parm$,device$}
  442.       Case 4
  443.         If eve=0
  444.           parm$="LMODE"
  445.         Else
  446.           parm$="HMODE"
  447.         EndIf
  448.         run_epu{parm$,device$}
  449.       Case 5
  450.         blocksize.l=GTGetInteger(0,5)
  451.         parm$="BLOCK "+UStr$(blocksize)
  452.         run_epu{parm$,device$}
  453.       Case 6
  454.         tablesize.l=GTGetInteger(0,6)
  455.         parm$="TABLE "+UStr$(tablesize)
  456.         run_epu{parm$,device$}
  457.     ;If user selected library by typing then run epu to set the change
  458.       Case 7
  459.         parm$="LIB "+GTGetString(0,7)
  460.         run_epu{parm$,device$}
  461.   ; Change device
  462.       Case 8
  463.         device$=GTGetString(0,8)
  464.         posn=Instr(device$,":")
  465.         If posn>0
  466.           device$=Left$(device$,posn-1)
  467.           inst.w=get_epudata{device$}
  468.           If inst<>1
  469.             not_installed{inst}
  470.           EndIf
  471.         Else
  472.           BeepScreen 0
  473.         EndIf
  474.   ;Select a device with the ASL path requester
  475.       Case 9
  476.         device$=ASLPathRequest$("Enter Device name",pa$)
  477.         posn=Instr(device$,":")
  478.         If posn>0
  479.           device$=Left$(device$,posn-1)
  480.           GTSetString 0,8,device$+":"
  481.           inst.w=get_epudata{device$}
  482.           If inst<>1
  483.             not_installed{inst}
  484.           EndIf
  485.         Else
  486.           BeepScreen 0
  487.         EndIf
  488.   ; Display a new window and select a compressor library
  489.       Case 10
  490.         Gosub _disable  ; Disable all gadgets in the main window
  491.         Window 1,380,110,186,134,$141E,"Select a Compressor",1,2
  492.  
  493.         AttachGTList 1,1
  494.  
  495.         ;Insert a slight delay before user can select a library
  496.         ResetTimer
  497.         Repeat
  498.           Wait
  499.         Until Ticks>30
  500.         Repeat
  501.           evil.l=WaitEvent
  502.         Until (evil=$200 OR evil=$40) AND EventWindow=1
  503.  
  504.         If evil=$40
  505.           gade.w=GadgetHit
  506.           eva.w=EventCode
  507.  
  508.       ;Find and set directory name from the item in the list selected.
  509.           If gade=0
  510.             ResetList directory()
  511.             For i.w=0 To eva
  512.               If NextItem(directory())
  513.               EndIf
  514.             Next i
  515.             GTEnable 0,7
  516.             GTSetString 0,7,directory()\name
  517.           EndIf
  518.         EndIf
  519.      ;Close window and run EPU to set the change
  520.         Free Window 1
  521.         Use Window 0
  522.         Gosub _enable
  523.         parm$="LIB "+GTGetString(0,7)
  524.         run_epu{parm$,device$}
  525.  
  526.      ;Run EPU to install it on the selected device.
  527.       Case 11
  528.         parm$=make_string{}
  529.         Execute_ &parm$,0,0
  530.         device$=GTGetString(0,8)
  531.         posn=Instr(device$,":")
  532.         If posn>0
  533.           device$=Left$(device$,posn-1)
  534.           inst.w=get_epudata{device$}
  535.           If inst<>1
  536.             not_installed{inst}
  537.           EndIf
  538.         Else
  539.           BeepScreen 0
  540.         EndIf
  541.  
  542.     ; Remove EPU from the selected device
  543.       Case 12
  544.         device$=GTGetString(0,8)
  545.         posn=Instr(device$,":")
  546.         If posn>0
  547.           device$=Left$(device$,posn-1)
  548.           parm$="EPU DEV "+device$+" KILL"
  549.           Execute_ &parm$,0,0
  550.           not_installed{0}
  551.         Else
  552.           BeepScreen 0
  553.         EndIf
  554.  
  555.  ;Modify the User-Startup file so EPU is run on boot-up.
  556.       Case 13
  557.         parm$=make_string{}
  558.         If OpenFile(0,"S:User-Startup")
  559.           FileSeek 0,Lof(0)
  560.           FileOutput 0
  561.           NPrint ""
  562.           NPrint"This line added by EPU GUI"
  563.           NPrint ""
  564.           NPrint parm$
  565.           NPrint ""
  566.           DefaultOutput
  567.           CloseFile 0
  568.         EndIf
  569.  
  570.   ;Quit the program
  571.       Case 15
  572.         Goto _kill
  573.     End Select
  574.   EndIf
  575. Forever
  576.  
  577. ;Close down application
  578. _kill:
  579. Gosub _disappear
  580. End
  581.  
  582. ;Open main window if not already done so
  583. _appear:
  584. If appear=False
  585.   Window 0,20,30,384,100,$100e,wintit$,1,2
  586.   AttachGTList 0,0 ; Attach the gadtools to the window
  587.   appear=True
  588. EndIf
  589. Return
  590.  
  591. ;Close the window if its open
  592. _disappear:
  593. If appear=True
  594.   CloseWindow 0
  595.   appear=False
  596. EndIf
  597. Return
  598.  
  599. ;Enable all the gadtools gadgets in the main window
  600. _enable:
  601.   state=True
  602.   For loop.b=1 To 15
  603.     GTEnable 0,loop
  604.   Next
  605.   Gosub _redraw
  606. Return
  607.  
  608. ;Disable the gadgets
  609. _disable:
  610.   state=False
  611.   For loop.b=1 To 15
  612.     GTDisable 0,loop
  613.   Next
  614.   Gosub _redraw
  615. Return
  616.  
  617. ;Redraw all the gadgets so they look as they should
  618. _redraw:
  619.   If appear=True
  620.     For loop.b=1 To 15
  621.       Redraw 0,loop
  622.     Next
  623.   EndIf
  624. Return
  625.  
  626. ;File Requester Icon. Wouldnt need to do this if Simon included Boopsi 
  627. ;support, or if I waited till the book I`ve ordered from the book-shop 
  628. ;comes in (Includes and AutoDocs)
  629. fileicon:
  630. IncBin "blitz-progs:epugui/filereq.shp"
  631.  
  632.